import Command

class Parser():
    '''
    The Parser class will parse each line from the server and determin how to 
    handle it. Possible ways to handle:
        Identify kinds of commands (raw, voting, games?)
        Run admin functions prifixed with botname(join, part, quit, etc. )
    '''

    def __init__(self, owner, admins, server):
        '''
        This init method sets up the Parser
        '''
        #The bot owner/operate/masterclassifyit
        self.owner = owner
        #List of approved admins
        self.admins = admins

        self.message = None

        self.server = server

        self.command = Command.Command(self.owner, self.admins, self.message, self.server)

        #start the parser
        self.parseEngine()

    def parseLine(self, line):
        '''This method takes a line from the server as input, and will parse it'''

        if len(line) >= 4:
            '''We know the message is PROBABLY parseable'''
            self.message = Message(line)
            #Now we have a line, check if its a command
            if self.message.message[0] == ':' + self.server.NICK:
                '''Message sent to me'''
                self.command = Command.MeCommand(self.owner, self.admins, self.server, self.message)
            elif self.message.message[0] == ':raw':
                '''This command is raw input'''

                pass

            '''Call command's execute method'''
            self.command.runCommand()


    def __sortMessage(self):
        '''This method is used to look at the first word and see what kind of command it is'''
        if (self.message.message[0] == 'raw'):
            pass

    def parseEngine(self):
        '''This method is the driver behind the parser. It will 
        loop through fetching new lines from the server and processing
        the messages
        '''
        while True:

            line = self.server.getLine()
            print(line)

        pass


